package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckgroupService;
import com.itheima.vo.CheckGroupEditVo;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckgroupController {

    @Reference
    CheckgroupService checkgroupService;

    @RequestMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup){
        try {
            //userSservice.getUserName();
            checkgroupService.add(checkGroup);
            return Result.success(MessageConstant.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }


    @RequestMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkGroup){
        try {
            checkgroupService.edit(checkGroup);
            return Result.success(MessageConstant.EDIT_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }



    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return checkgroupService.findPage(queryPageBean);
    }

    @RequestMapping("/findByIdBatch")
    public Result findByIdBatch(Integer id){
        CheckGroupEditVo checkGroupEditVo = checkgroupService.findByIdBatch(id);
        return Result.success("",checkGroupEditVo);
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        List<CheckGroup> checkGroups = checkgroupService.findAll();
        return Result.success("",checkGroups);
    }
}
